from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPUSpecification, SPU
from apps.meiduo_admin.serializers.specs import SpecsSerializers, SPUserializers
from apps.meiduo_admin.utils import PageNum


class SpecsView(ModelViewSet):
    # 指定序列化器
    serializer_class = SpecsSerializers
    # 指定查询集
    queryset = SPUSpecification.objects.all()

    # 指定分页器
    pagination_class = PageNum

    #自定义获取SPU商品数据
    def simple(self,request):
        # 1.查询所有的SPU数据
        spu = SPU.objects.all()
        # 2.进行序列化返回
        ser = SPUserializers(spu,many=True)
        return Response(ser.data)